package yxy.game.pm2.bean.module;

import java.util.concurrent.TimeUnit;

import org.redisson.api.RLock;

public class RedisLock {
	private RLock rLock;

	public RedisLock(RLock rLock) {
		this.rLock = rLock;
	}

	public boolean tryLock() throws InterruptedException {
		return rLock.tryLock(20, 10, TimeUnit.SECONDS);
	}

	public void unlock() {
		if (this.rLock.isHeldByCurrentThread() && this.rLock.isLocked()) {
			this.rLock.unlock();
		}
	}

}
